/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.siox.util;

import java.util.Vector;

/**
 *
 * @author Lindily
 */
public class KeywordVector {

    private Vector<String> keywordVector = new Vector<String>();
    private int thisNo = -1;
    private String word;

    public void add(String keyword) {
        keywordVector.add(keyword);
        thisNo = keywordVector.size() - 1;
        System.out.print("keywordVector.size() " + keywordVector.size());
        System.out.print("         thisNo " + thisNo);
        System.out.println("       keyword: "+keyword);
    }

    public String previous() {
        System.out.println("up-->thisNo " + thisNo);
        if (-1 == thisNo) {
            word = "";
        } else {
            word = keywordVector.get(Math.abs(--thisNo));  //这里特别注意 thisNo-- 当thisNo=0 --后 Math.abs()无法捕捉--后的值
            if(-1==thisNo){
                thisNo=0;
            }
        }
        return word;
    }

    public String next() {
        System.out.println("next-->thisNo " + thisNo);
        if (-1 == thisNo) {
            word = "";
        } else {
            if (thisNo < keywordVector.size()) {
                word = keywordVector.get(thisNo++);
                if (thisNo == keywordVector.size()) {
                    thisNo = keywordVector.size() - 1;
                }
            }
        }
        return word;
    }
}
